package com.ruoyi.project.mahjong.controller;

import java.util.List;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.project.mahjong.domain.DeskMember;
import com.ruoyi.project.mahjong.domain.MyConstat;
import com.ruoyi.project.mahjong.domain.vo.DeskIngVo;
import com.ruoyi.project.mahjong.service.IDeskMemberService;
import com.ruoyi.project.system.service.ISysDictDataService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.mahjong.domain.DeskIng;
import com.ruoyi.project.mahjong.service.IDeskIngService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 开桌情况Controller
 *
 * @author ruoyi
 * @date 2023-07-26
 */
@RestController
@RequestMapping("/mahjong/desking")
public class DeskIngController extends BaseController
{
    @Autowired
    private IDeskIngService deskIngService;
    @Autowired
    private IDeskMemberService deskMemberService;
    @Autowired
    private ISysDictDataService dictDataService;
    /**
     * 查询开桌情况列表
     */
    @PreAuthorize("@ss.hasPermi('mahjong:desking:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeskIng deskIng)
    {
        startPage();
        List<DeskIng> list = deskIngService.selectDeskIngList(deskIng);

//        for(DeskIng member:list){
//            member.setIntegral(dictDataService.selectDictLabel(member.getMode(),member.getIntegral()));
//        }
        return getDataTable(list);
    }

    /**
     * 成局List集合
     * @param deskIng
     * @return
     */
    @GetMapping("/chengjuList")
    public   AjaxResult chengjuList(DeskIng deskIng)
    {
        deskIng.setStatus(MyConstat.CHEGN_JU);
        deskIng.setBak3(MyConstat.DESK_ING);
        List<DeskIngVo> list = deskIngService.chengjuList(deskIng);
        return AjaxResult.success(list);
    }
    /**
     * 开始List集合
     * @param deskIng
     * @return
     */
    @GetMapping("/startList")
    public   AjaxResult startList(DeskIng deskIng)
    {
        deskIng.setStatus(MyConstat.START);
        deskIng.setBak3(MyConstat.DESK_ING);
        List<DeskIngVo> list = deskIngService.chengjuList(deskIng);
        return AjaxResult.success(list);
    }
    /**
     * 结束List集合
     * @param deskIng
     * @return
     */
    @GetMapping("/finishList")
    public   TableDataInfo finishList(DeskIng deskIng)
    {
        deskIng.setStatus(MyConstat.FINISH);
        deskIng.setBak3(MyConstat.DESK_FINISH);
        startPage();
        List<DeskIng> deskIngList=deskIngService.selectFinshList(deskIng);
        TableDataInfo info=new TableDataInfo();
        info.setCode(HttpStatus.SUCCESS);
        info.setTotal(new PageInfo(deskIngList).getTotal());
        List<DeskIngVo> list = deskIngService.coverList(deskIngList);
        info.setRows(list);
        return info;
    }
    /**
     * 开局
     * @param id 开桌id
     * @return
     */
    @GetMapping("/goStart/{id}")
    public   AjaxResult goStart(@PathVariable Long  id)
    {
//        开桌
        deskIngService.goStart(id);
        return AjaxResult.success();
    }
//    撤回
    @GetMapping("/endRollback/{id}")
    public   AjaxResult endRollback(@PathVariable Long  id)
    {
//        撤回
        deskIngService.endRollback(id);
        return AjaxResult.success();
    }
    /**
     * 开局
     * @param id 开桌id
     * @return
     */
    @GetMapping("/goFinish/{id}")
    public   AjaxResult goFinish(@PathVariable Long  id)
    {

        deskIngService.goFinish(id);
        return AjaxResult.success();
    }
    /**
     * 开局后的人员信息列表
     * @param id 开桌id
     * @return
     */
    @GetMapping("/deskMemberList/{id}")
    public   AjaxResult deskMemberList(@PathVariable Long  id)
    {
        DeskMember member=new DeskMember();
        member.setDeskId(id);
        member.setBak3(MyConstat.DESK_ING);
        List<DeskMember> memberList=  deskMemberService.selectDeskMemberList(member);
        return AjaxResult.success(memberList);
    }

    /**
     * 导出开桌情况列表
     */
    @PreAuthorize("@ss.hasPermi('mahjong:desking:export')")
    @Log(title = "开桌情况", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DeskIng deskIng)
    {
        List<DeskIng> list = deskIngService.selectDeskIngList(deskIng);
        ExcelUtil<DeskIng> util = new ExcelUtil<DeskIng>(DeskIng.class);
        return util.exportExcel(list, "desking");
    }

    /**
     * 获取开桌情况详细信息
     */
    @PreAuthorize("@ss.hasPermi('mahjong:desking:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(deskIngService.selectDeskIngById(id));
    }

    /**
     * 新增开桌情况
     */
    @PreAuthorize("@ss.hasPermi('mahjong:desking:add')")
    @Log(title = "开桌情况", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeskIng deskIng)
    {
        return toAjax(deskIngService.insertDeskIng(deskIng));
    }

    /**
     * 修改开桌情况
     */
    @PreAuthorize("@ss.hasPermi('mahjong:desking:edit')")
    @Log(title = "开桌情况", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeskIng deskIng)
    {
        return toAjax(deskIngService.updateDeskIng(deskIng));
    }

    /**
     * 删除开桌情况
     */
    @PreAuthorize("@ss.hasPermi('mahjong:desking:remove')")
    @Log(title = "开桌情况", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(deskIngService.deleteDeskIngByIds(ids));
    }
}
